home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 March / Macworld CD-ROM (March 1995).cdr / Updaters / AppMaker 1.5.2->1.5.4 / Libraries / THINK / AMClassLibC / CLabeledGroup.cp < prev    next >
Encoding:
Text File  |  1992-03-20  |  4.7 KB  |  188 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CLabeledGroup.c
  3.         
  4.     A class to manage a radiogroup, except that there is a title (like in
  5.     MacApp clusters).
  6.  
  7.     SUPERCLASS = CRadioGroupPane
  8.     
  9.     Copyright © 1991 Bowers Development Corporation. All rights reserved.
  10.  
  11.  ******************************************************************************/
  12.  
  13. #include <TBUtilities.h>
  14. #include <CPaneBorder.h>
  15. #include "CAMIconPane.h"
  16. #include "CLabeledGroup.h"
  17.  
  18. #define kLabelIndent    12
  19. #define kLabelMargin    4
  20.  
  21. #define LINEHEIGHT(f)    ((f.ascent) + (f.descent) + (f.leading))    
  22.  
  23. /*----------*/
  24. void CLabeledGroup::ILabeledGroup    (CView            *anEnclosure, 
  25.                                      CBureaucrat    *aSupervisor,
  26.                                      short            aWidth,
  27.                                      short            aHeight,
  28.                                      short            aHEncl,
  29.                                      short            aVEncl,
  30.                                      SizingOption    aHSizing,
  31.                                      SizingOption    aVSizing,
  32.                                      short            aThickness,
  33.                                      short            aDropShadow,
  34.                                      Str255            aLabel,
  35.                                      short            aTextStyle,
  36.                                      short            aTextSize,
  37.                                      Str255            aFontName)
  38. {
  39.     StylesRec            styles;
  40.  
  41.     theLabel = NULL;
  42.  
  43.     CRadioGroupPane::IRadioGroupPane (anEnclosure, aSupervisor,
  44.                                         aWidth, aHeight, aHEncl, aVEncl,
  45.                                         aHSizing, aVSizing);
  46.  
  47.     styles.textStyle = aTextStyle;
  48.     styles.textSize = aTextSize;
  49.     CopyPString (aFontName, styles.fontName);
  50.     ILabeledGroupX (aThickness, aDropShadow, aLabel, &styles);
  51.  
  52. } /* ILabeledGroup */
  53.  
  54. /*----------*/
  55. void CLabeledGroup::IViewTemp        (CView            *anEnclosure,
  56.                                       CBureaucrat    *aSupervisor,
  57.                                      Ptr            viewData)
  58. {
  59.     register CLabeledGroupTempP        p;
  60.     short            strSize;
  61.     StylesP            stylesPtr;
  62.  
  63.     theLabel = NULL;
  64.  
  65.     p = (CLabeledGroupTempP) viewData;
  66.     inherited::IViewTemp (anEnclosure, aSupervisor, (Ptr)&p->sRadioGroupPaneTemp);
  67.     strSize = 1 + p->label [0];
  68.     strSize += (strSize & 1);        // bump to even number
  69.     stylesPtr = (StylesP) &p->label [strSize];
  70.     ILabeledGroupX (p->thickness, p->dropShadow, p->label, stylesPtr);
  71.  
  72. } /* IViewTemp */
  73.  
  74. /*----------*/
  75. void CLabeledGroup::ILabeledGroupX    (short            aThickness,
  76.                                      short            aDropShadow,
  77.                                      Str255            aLabel,
  78.                                      StylesP        p)
  79. {
  80.     /* do no additional initialization if there is no label. */
  81.  
  82.     if (aLabel [0] != 0) {
  83.         theLabel = NewString (aLabel);
  84.         AMSetupTextEnvirons (this, p);
  85.         MakeBorder (aThickness, aDropShadow);
  86.     }
  87.     radioStation = NULL;
  88.  
  89. } /* ILabeledGroupX */                         
  90.  
  91. /*----------*/
  92. void CLabeledGroup::Dispose            (void)
  93. {
  94.     if (theLabel != NULL) {
  95.         DisposHandle ((Handle)theLabel);
  96.         theLabel = NULL;
  97.     }
  98.     inherited::Dispose ();
  99.  
  100. } /* Dispose */
  101.  
  102. /*----------*/
  103. void CLabeledGroup::MakeBorder        (short            aThickness,
  104.                                      short            aDropShadow)
  105. {
  106.     CPaneBorder        *border;
  107.     Rect            margin;
  108.     FontInfo        fInfo;
  109.  
  110.     border = new (CPaneBorder);
  111.     border->IPaneBorder (kBorderFrame);
  112.     
  113.     Prepare ();
  114.     GetFontInfo (&fInfo);
  115.     
  116.     SetRect (&margin, 0, LINEHEIGHT (fInfo) / 2, 0, 0);
  117.     border->SetMargin (&margin);
  118.     border->SetPenSize (aThickness, aThickness);
  119.     if (aDropShadow > 0) {
  120.         border->SetShadow (2, 2, aThickness, aThickness);        /* ?? */
  121.     }
  122.     SetBorder (border);
  123.  
  124. } /* MakeBorder */
  125.  
  126. /*----------*/
  127. void CLabeledGroup::Draw            (Rect            *area)
  128. {
  129.     Rect            labelRect;
  130.     FontInfo        fInfo;
  131.     short            sWidth;
  132.     short            vLoc;
  133.     Str255            labelStr;
  134.     
  135.     /* if there is no label, do nothing. */
  136.  
  137.     if (theLabel != NULL) {
  138.         HLock ((Handle)theLabel);
  139.         CopyPString(&(**theLabel), labelStr);    /* use local variable. */
  140.         HUnlock ((Handle)theLabel);
  141.     
  142.         GetFontInfo (&fInfo);
  143.         sWidth = StringWidth (labelStr);
  144.  
  145.         labelRect.top = 0;
  146.         labelRect.left = kLabelIndent;
  147.         labelRect.right = labelRect.left + kLabelMargin + sWidth + kLabelMargin;
  148.         labelRect.bottom = LINEHEIGHT (fInfo);
  149.         EraseRect (&labelRect);        
  150.         
  151.         /* move to the text baseline, which is top of rectangle - font ascent.    */
  152.         vLoc = fInfo.ascent;
  153.         MoveTo (kLabelIndent + kLabelMargin, vLoc); 
  154.         DrawString (labelStr);        
  155.     }
  156.  
  157. } /* Draw */
  158.  
  159. /******************************************************************************
  160.  ProviderChanged
  161.  
  162.      Respond to a change in a provider. The only provider this class
  163.      knows about is CAMIconPane. When it receives notification that
  164.      a radio control has been selected, the CLabeledGroup turns off
  165.      the previously selected icon and updates the radioStation
  166.      instance variable to refer to the newly selected icon.
  167. ******************************************************************************/
  168.  
  169. void CLabeledGroup::ProviderChanged    (CCollaborator    *aProvider,
  170.                                      long            reason,
  171.                                      void            *info)
  172. {
  173.     if (member (aProvider, CAMIconPane))
  174.     {
  175.         if ((reason == radioChanged) && ((*(Boolean*)info) == TRUE))
  176.         {
  177.             if (radioStation != NULL) {
  178.                 radioStation->SetRadio (FALSE);
  179.             }
  180.             radioStation = (CAMIconPane*) aProvider;
  181.         }
  182.     }
  183.     inherited::ProviderChanged (aProvider, reason, info);
  184.  
  185. } /* ProviderChanged */
  186.  
  187. /* CLabeledGroup */
  188.